package jdbc;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class JDBCDemo5 {
    public static void main(String[] args) {
        try(
                Connection connection = DBUtil.getConnection();
                ){
         Statement statement = connection.createStatement();
            String sql = "SELECT t.name,t.salary,t.title,c.name,c.floor " +
                    "FROM teacher t " +
                    "JOIN class c ON t.id=c.teacher_id " +
                    "WHERE t.name='王克晶' ";
            ResultSet rs = statement.executeQuery(sql);
            while (rs.next()) {
                String name = rs.getString("t.name");
                int salary = rs.getInt("t.salary");
                String title = rs.getString("c.name");
                String floor = rs.getString("c.floor");
                System.out.println(name + "," + salary + "," + title + "," + floor);
            }

        } catch (Exception e) {
            e.printStackTrace();
        }
    }

}
